﻿using IPluginInterface;
using Qting.AOI.Serialize;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using YiNing.Tools;

namespace MesTest
{
    [Serializable]
    public class MesPlugin : MarshalByRefObject, IAoiPlugin
    {
        public string Tag
        {
            get;
            private set;
        }

        public Version Version
        {
            get;
            private set;
        }

        public string Description
        {
            get;
            private set;
        }


        public MesPlugin()
        {
            Tag = "Mes插件";
            Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            Description = "mes插件测试";
        }
        public PluginResult Init(params object[] args)
        {
          
            return new PluginResult();
        }

        public PluginResult Start(ref AoiPcbs aoiPcbs, bool bDual = false, params object[] args)
        {
            //aoiPcbs.pcb_name = "Start";
            return new PluginResult();
        }

        public PluginResult BeforeProductIn(ref AoiPcbs aoiPcbs, bool bDual = false, params object[] args)
        {
            //aoiPcbs.pcb_name = "BeforeProductIn";
            return new PluginResult();
        }
        public PluginResult ProductIn(ref AoiPcbs aoiPcbs, bool bDual = false, params object[] args)
        {
            PluginResult pluginResult = new PluginResult();
            aoiPcbs.m_barcodeList.Add(new tagBarcodeInfo() { strBarcode = "1", FunctionType = 0, subBoard = 1, unionBoard = 1 });
            aoiPcbs.m_barcodeList.Add(new tagBarcodeInfo() { strBarcode = "2", FunctionType = 0, subBoard = 2, unionBoard = 1 });
            aoiPcbs.m_barcodeList.Add(new tagBarcodeInfo() { strBarcode = "3", FunctionType = 0, subBoard = 3, unionBoard = 1 });
            aoiPcbs.m_barcodeList.Add(new tagBarcodeInfo() { strBarcode = "4", FunctionType = 0, subBoard = 4, unionBoard = 1 });
            aoiPcbs.m_barcodeList.Add(new tagBarcodeInfo() { strBarcode = "5", FunctionType = 0, subBoard = 5, unionBoard = 1 });
            aoiPcbs.m_barcodeList.Add(new tagBarcodeInfo() { strBarcode = "6", FunctionType = 0, subBoard = 6, unionBoard = 1 });
            JsonHelper.Serialize(aoiPcbs, "D:/ProductIn.json");
            return pluginResult;
        }

        public PluginResult AfterProductIn(ref AoiPcbs aoiPcbs, bool bDual = false, params object[] args)
        {
            //aoiPcbs.pcb_name = "AfterProductIn";
            JsonHelper.Serialize(aoiPcbs, "D:/AfterProductIn.json");
            return new PluginResult();
        }
        public PluginResult BeforeProductOut(ref AoiPcbs aoiPcbs, bool bDual = false, params object[] args)
        {
            //aoiPcbs.pcb_name = "BeforeProductOut";
            JsonHelper.Serialize(aoiPcbs, "D:/BeforeProductOut.json");
            return new PluginResult();
        }

        public PluginResult ProductOut(ref AoiPcbs aoiPcbs, bool bDual = false, params object[] args)
        {
            PluginResult pluginResult = new PluginResult();
            string res = ""; 
            JsonHelper.Serialize(aoiPcbs, "D:/ProductOut.json");
            return pluginResult;
        }

        public PluginResult AfterProductOut(ref AoiPcbs aoiPcbs, bool bDual = false, params object[] args)
        {
            JsonHelper.Serialize(aoiPcbs, "D:/AfterProductOut.json");
            return new PluginResult();
        }

        public PluginResult Done(ref AoiPcbs aoiPcbs, bool bDual = false, params object[] args)
        {
            JsonHelper.Serialize(aoiPcbs, "D:/Done.json");
            return new PluginResult();
        }

        public void OpenSettingForm(params object[] args)
        {
            //new Setting(baseParameters, parameters1, parameters2).ShowDialog();
        }
             public PluginResult YiNing(ref AoiPcbs spiPcbs, params object[] args)
        {
            throw new NotImplementedException();
        }

        public void Dispose()
        {
            //throw new NotImplementedException();
        }
    }
}
